<?php

use Lg\View\JsBlock;
use Lg\View\Asset;

//kindeditor
Asset::addCss(root_url('/assets/editor/themes/simple/simple.css'));
Asset::addJs(root_url('/assets/editor/kindeditor-min.js'), Asset::BODY_END);
Asset::addJs(root_url('/assets/editor/lang/zh_CN.js'), Asset::BODY_END);
//jquery chosen
Asset::addCss(root_url('/assets/jquery-chosen/chosen.min.css'));
Asset::addJs(root_url('/assets/jquery-chosen/chosen.jquery.min.js'), Asset::BODY_END);
Asset::addJsBlock('$(".chzn-select").chosen();', Asset::BODY_END);

//datepicker
Asset::addCss(root_url('/assets/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css'));
Asset::addJs(root_url('/assets/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js'), Asset::BODY_END);
Asset::addJs(root_url('/assets/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js'), Asset::BODY_END);
JsBlock::begin(Asset::DOM_READY);
?>
<script>
    $('.datepicker').datetimepicker({format: 'yyyy-mm-dd hh:ii:ss', todayBtn: true, language: 'zh-CN'});
</script>
<?php JsBlock::end(); ?>
<?php echo get_header(); ?>
<form class="form-horizontal" action="" method="post">
    <div class="row">
        <div class="col-md-12">
            <ul class="nav nav-tabs" role="tablist">
                <li class="nav-item">
                    <a class="nav-link active" data-toggle="tab" href="#settings" role="tab" aria-controls="settings" aria-expanded="true"><i class="icon-calculator"></i> 基本信息</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" data-toggle="tab" href="#general" role="tab" aria-controls="general" aria-expanded="false"><i class="icon-basket-loaded"></i> 常规设置</a>
                </li>                      
            </ul>


            <div class="tab-content">
                <div class="tab-pane active" id="settings">
                    <ul class="nav nav-tabs" role="tablist">                                      
                        <?php foreach ($languages as $language) { ?>
                            <li class="nav-item">
                                <a class="nav-link <?php
                                if (get_option('system.admin_language', 'zh_CN') == $language->directory) {
                                    echo 'active';
                                }
                                ?>" href="#language<?php echo $language->language_id; ?>" data-toggle="tab" aria-expanded="true">
                                    <span class="flag flag-<?php echo $language->code; ?>" ></span> <?php echo $language->name; ?></a></li>                        
                        <?php } ?>

                    </ul>
                    <div class="tab-content">
                        <?php
                        foreach ($languages as $language) {
                            $lang_id = $language->language_id;
                            ?>                        
                            <div class="tab-pane active" id="language<?php echo $language->language_id; ?>" role="tabpanel" aria-expanded="true">
                               
                                <div class="form-group row required">
                                    <label class="col-sm-2 control-label" for="node_title<?php echo $language->language_id; ?>">文章标题</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="language[<?php echo $language->language_id; ?>][node_title]" value="<?php echo $node_languages[$lang_id]->node_title; ?>" placeholder="请输入文章标题" id="node_title<?php echo $language->language_id; ?>" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group row required">
                                    <label class="col-sm-2 control-label" for="node_content<?php echo $language->language_id; ?>">文章内容</label>
                                    <div class="col-sm-10">
                                        <textarea style="width:100%;" rows="14"  name="language[<?php echo $language->language_id; ?>][node_content]" placeholder="描述" id="node_content<?php echo $language->language_id; ?>" ><?php echo $node_languages[$lang_id]->node_content; ?></textarea>
                                    </div>
                                </div>
                                <div class="form-group row required">
                                    <label class="col-sm-2 control-label" for="meta_keywords<?php echo $language->language_id; ?>">关键词</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="language[<?php echo $language->language_id; ?>][meta_keywords]" value="<?php echo $node_languages[$lang_id]->meta_keywords; ?>" placeholder="Meta tag 关键词" id="description<?php echo $language->language_id; ?>" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group row required">
                                    <label class="col-sm-2 control-label" for="meta_description<?php echo $language->language_id; ?>">关键词描述</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="language[<?php echo $language->language_id; ?>][meta_description]" value="<?php echo $node_languages[$lang_id]->meta_description; ?>" placeholder="Meta tag 关键词描述" id="description<?php echo $language->language_id; ?>" class="form-control">
                                    </div>
                                </div>
                            </div>
                            <?php JsBlock::begin(Asset::DOM_READY) ?>
                            <script>
                                KindEditor.create('#node_content<?php echo $language->language_id; ?>', {
                                    themeType: 'simple'
                                });
                            </script>
                            <?php JsBlock::end() ?>

                        <?php } ?>
                    </div>
                    <br/>
                    <button type="submit" class="btn btn-md btn-success pull-right">保存</button><br/><br/>


                </div>
                <!-- /.tab-pane -->   
                <div class="tab-pane" id="general">

                    <div class="form-group row required">
                        <label class="col-sm-2 control-label" for="parent_id">分类目录</label>
                        <div class="col-sm-10">
                            
                            <div class="card">
                                <div class="card-block" style="height: 200px;overflow-y: scroll;background-color: #f9f9f9;">
                                    <?php foreach ($categories as $cat) { ?>
                                    <div style="margin:10px 0;">
                                            <label style="margin-left:<?php echo ($cat->depth - 1) * 18; ?>px">
                                                <input type="checkbox" name="node_category[]" <?php echo value_condition(in_array($cat->category_id, $node_category), 'checked'); ?> value="<?php echo $cat->category_id; ?>" />
                                                <?php
                                                echo $cat->title;
                                                ?></label>
                                        </div>
                                    <?php } ?>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-2 control-label" style="padding-top:0;">状态</label>
                        <div class="col-sm-10">
                            <label class="label-radio inline">
                                <input type="radio" name="node[node_status]" <?php
                                echo value_condition($node->node_status == 'publish', 'checked="true"'), value_condition(!isset($node), 'checked="true"');
                                ?> id="node_status1" value="publish" />
                                <span class="custom-radio"></span>
                                发布
                            </label>
                            <label class="label-radio inline">
                                <input type="radio" name="node[node_status]" id="node_status2" value="private" <?php
                                echo value_condition($node->node_status == 'private', 'checked="true"');
                                ?> />
                                <span class="custom-radio"></span>
                                私有
                            </label>
                        </div><!-- /.col -->
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 control-label" style="padding-top:0;">文章评论</label>
                        <div class="col-sm-10">
                            <label class="label-radio inline">
                                <input type="radio" name="node[comment_status]" checked="true" id="comment_status1" value="open" />
                                开启
                            </label>
                            <label class="label-radio inline">
                                <input type="radio" name="node[comment_status]" id="comment_status2" value="closed" />
                                关闭
                            </label>
                        </div><!-- /.col -->
                    </div>

                    <div class="form-group row required">
                        <label class="col-sm-2 control-label" for="click_count">点击数</label>
                        <div class="col-sm-10">
                            <input name="node[click_count]" id="click_count" class="form-control" value="<?php
                            echo value_condition($node->click_count, $node->click_count, 0);
                            ?>" placeholder="文章点击数量" />
                        </div>
                    </div> 

                    <div class="form-group row required">
                        <label class="col-sm-2 control-label" for="node_date">发布时间</label>
                        <div class="col-sm-10">
                            <input name="node[node_date]" id="node_date" class="form-control datepicker " value="<?php echo $node->node_date ? $node->node_date : date('Y-m-d H:i:s'); ?>" placeholder="文章点击数量" />
                        </div>
                    </div> 

                    <div class="form-group row">
                        <div class="col-sm-12">
                        <button type="submit" class="btn btn-success pull-right">保存设置</button>
                        </div>
                    </div>
                    <!-- /.box-footer -->
                </div>

            </div>

        </div>
        <!-- /.col -->
    </div>
    <!-- /.row -->


</form>

<?php echo get_footer(); ?>